package com.hrg.rds.biz.waybill.domain.template.cmd;

import com.hrg.rds.biz.waybill.domain.template.ParamType;
import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class CmdParam {
    // Simple、Expression
    private CmdParamType cmdParamType;
    
    private String key;
    
    private String value;

    private String evaluatedValue;

    // 是否必填
    private boolean required;

    private ParamType paramType;

    public String getEvaluatedValue() {
        return cmdParamType == CmdParamType.Simple ? value : evaluatedValue;
    }

    public Double getDoubleEvaluatedValue() {
        return Double.valueOf(getEvaluatedValue());
    }
    public Boolean getBooleanEvaluatedValue() {
        return Boolean.valueOf(getEvaluatedValue());
    }
    public int getIntegerEvaluatedValue() {
        return Integer.parseInt(getEvaluatedValue());
    }
    public Object getObjectEvaluatedValue() {
        Class<?> clazz = this.paramType.getClazz();
        return clazz.cast(getEvaluatedValue());
    }
}
